<template>
	<view class="content">
		<u-navbar :is-back="false" title="" :background="background">
			<view class="slot-wrap u-flex">
				<view class="navbar_msg">
					<image src="../../static/navbar_msg.png" mode=""></image>
				</view>
				<u-search placeholder="请输入关键字" shape="round" v-model="keyword" :animation="true" :show-action="false"
					@focus="search" @search="search">
				</u-search>
				<view class="navbar_sys">
					<image src="../../static/navbar_sys.png" mode=""></image>
				</view>
			</view>
		</u-navbar>
		<scroll-view scroll-x="true" class="one" :scroll-into-view="scrollIntoIndex">
			<view 
			   :id="'top'+index"
			   class="one_one" 
			   v-for="(item,index) in topBar"    
			   :key="index"
			   @tap="changeTba(index)"
			>
				<text :class="topBarIndex===index?'selected_color':''">{{item.title}}</text>
			</view>
		</scroll-view>
		<swiper @change="onchangeTab" :current="topBarIndex" :style="'height:'+clientHeight+'px;'">
			<swiper-item v-for="(item,index) in topBar" :key="index">
				<view class="home-data">
					<IndexSwiper :dataList="swiperList"></IndexSwiper>
					<Noticebar></Noticebar>
					<goodsicon></goodsicon>
					<Hot></Hot>
					<Card cardTitle='今日上新'></Card>
					<Recommend></Recommend>
					<Card cardTitle='猜你喜欢'></Card>
				</view>
			</swiper-item>
		</swiper>
		<Goodslikes></Goodslikes>
	</view>
</template>

<script>
	import goods from '../../components/common/goods.vue'
	import IndexSwiper from '../../components/index/IndexSwiper.vue'
	import Recommend from '../../components/index/Recommend.vue'
	import goodsicon from '../../components/index/goodsicon.vue'
	import Noticebar from '../../components/index/Noticebar.vue'
	import Goodslikes from '../../components/index/Goodslikes.vue'
	import Card from '../../components/index/Card.vue'
	import Hot from '../../components/index/Hot.vue'
	export default {
		components: {
			goods,IndexSwiper,Recommend,goodsicon,Noticebar,Goodslikes,Card,Hot
		},
		data() {
			return {
				//选中的索引
				topBarIndex:0,
				scrollIntoIndex:"top0",  //顶栏跟随索引值
				background: {
					backgroundColor: '#eed8aa',
				},
				//内容块的高度值
				clientHeight:0,
				keyword: '',
				// 顶栏数据
				"topBar":[
					{
						"title":"推荐",
					},
					{
						"title":"热点",
					},
					{
						"title":"财经",
					},
					{
						"title":"娱乐",
					},
					{
						"title":"军事",
					},
					{
						"title":"运动",
					},
					
				],
				"swiperList": [{
						"id": 1,
						"image": "https://img.zcool.cn/community/0101b35ad80b5fa8012040295a4b02.jpg?x-oss-process=image/auto-orient,1/resize,m_lfit,w_1280,limit_1/sharpen,100/format,webp/quality,q_100"
					},
					{
						"id": 2,
						"image": "https://i.pinimg.com/736x/b9/b3/31/b9b331400113869f2d0cddb1f790da3c.jpg"
					},
					{
						"id": 3,
						"image": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTrccSBdBN1kYU_vOP6pvrcslheL-TjQhq_rA&usqp=CAU"
					}
				],
			}
		},
		onReady() {
			let view = uni.createSelectorQuery().select(".home-data")
			view.boundingClientRect(data=>{
				this.clientHeight = data.height
				console.log(data.height);
			}).exec()
		},
		methods: {
			search() {
				uni.navigateTo({
					url: "/pages/search_result/index"
				})
			},
			changeTba(index){
				if(this.topBarIndex===index){
					return
				}else{
					this.topBarIndex=index
					this.scrollIntoIndex = 'top'+index
				}
			},
			//获取可视区域高度（兼容）
			getclientHeight(){
				const res = uni.getSystemInfoSync()
				// console.log(res.statusBarHeight);
				const system = res.osName
				if(system==='ios'){
					return 44+res.statusBarHeight
				}else if(system==='android'){
					return 48+res.statusBarHeight
				}else{
					return 0
				}
			},
			goDetails(){
				uni.navigateTo({
					url:'/pages/details/details'
				})
			},
			onchangeTab(e){
				this.changeTba(e.detail.current)
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		background-color: #eeeeee;
		// height: 800rpx;
		padding-bottom: 40rpx;
	}

	.notice-bar {
		padding-top: 10rpx;
	}

	.slot-wrap {
		display: flex;
		align-items: center;
		/* 如果您想让slot内容占满整个导航栏的宽度 */
		flex: 1;
		/* 如果您想让slot内容与导航栏左右有空隙 */
		/* padding: 0 30rpx; */
	}

	.navbar_msg {
		image {
			width: 52rpx;
			height: 52rpx;
			padding-left: 40rpx;
			padding-right: 20rpx;
		}
	}

	.navbar_sys {
		image {
			width: 54rpx;
			height: 52rpx;
			margin: 0 40rpx 0 20rpx;
		}
	}

	.likes {
		display: flex;
		justify-content: center;
		font-weight: bold;
		font-size: 32rpx;
		margin: 20rpx auto;

		view {
			margin-left: 20rpx;
		}

	}

	.one {
		padding-top: 20rpx;
		font-size: 32rpx;
		width: 100%;
		height: 70rpx;
		white-space: nowrap;

		.one_one {
			// text-align: center;
			padding: 0rpx 46rpx;
			display: inline-block;
		}
		.selected_color{
			padding: 10rpx 0;
			border-bottom: 2px solid #f5a300;
			color: #f5a300;
		}
		.noselected_color{
			padding: 10rpx 0;
			// border-bottom: 1px solid #f5a300;
			color: #000000;
		}
	}

	.two {
		width: 700rpx;
		margin: 0rpx auto;
		background-color: #ffffff;
		border-radius: 20rpx;

		.two_one>view {
			margin: 20rpx auto;

			.two_one_one {
				margin: 0 auto;
			}
		}

		image {
			width: 72rpx;
			height: 72rpx;
			// padding-left: 5rpx;
			border-radius: 50%;
		}

		.two_title {
			// text-align: center;
			font-size: 22rpx;
		}
	}

	.three {
		width: 700rpx;
		margin: 20rpx auto;
		padding-top: 10rpx;
		background-color: #ffffff;
		border-radius: 20rpx;

		image {
			width: 34rpx;
			height: 34rpx;
		}

		view {
			width: 20rpx;
		}

		.hot_1 {
			width: 100%;
			height: 60rpx;
			padding: 20rpx;
			padding-top: 30rpx;
		}

		text {
			margin-left: 372rpx;
		}

		.three_one {
			width: 96%;
			margin: 20rpx auto;
			padding-bottom: 20rpx;
			// background-color: #f5a300;
			white-space: nowrap;

			.three_one_one {
				width: 200rpx;
				height: 200rpx;
				justify-content: center;
				align-items: center;
				margin-left: 20rpx;
				display: inline-block;

				image {
					width: 196rpx;
					height: 196rpx;
					border-radius: 30rpx;
				}
			}
		}
	}

	.four {
		width: 96%;
		margin: 0rpx auto;

		// background-color: red;
		.four_left {
			width: 50%;
			height: 600rpx;
			background-color: #00ffff;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.four_right {
			width: 50%;
			height: 600rpx;
			background-color: #5500ff;

			.four_right1 {
				height: 300rpx;
				background-color: mediumvioletred;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.four_right2 {
				height: 300rpx;
				background-color: pink;

				image {
					width: 100%;
					height: 100%;
				}
			}
		}
	}

	.demo-warter {
		border-radius: 8px;
		margin: 5px;
		background-color: #ffffff;
		padding: 8px;
		position: relative;
	}

	.u-close {
		position: absolute;
		top: 32rpx;
		right: 32rpx;
	}

	.demo-image {
		width: 100%;
		border-radius: 4px;
	}

	.demo-title {
		font-size: 34rpx;
		margin-top: 5px;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
		color: #333333;
		word-break: break-all;
		padding: 6rpx 0;
		// color: $u-main-color;
	}

	.demo-tag {
		display: flex;
		margin-top: 5px;
	}

	.demo-tag-owner {
		background-color: $u-type-error;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		padding: 4rpx 14rpx;
		border-radius: 50rpx;
		font-size: 20rpx;
		line-height: 1;
	}

	.demo-tag-text {
		border: 1px solid $u-type-primary;
		color: $u-type-primary;
		margin-left: 10px;
		border-radius: 50rpx;
		line-height: 1;
		padding: 4rpx 14rpx;
		display: flex;
		align-items: center;
		border-radius: 50rpx;
		font-size: 20rpx;
	}

	.demo-price {
		font-size: 30rpx;
		color: $u-type-error;
		margin-top: 5px;
	}

	.demo-shop {
		font-size: 22rpx;
		color: $u-tips-color;
		margin-top: 5px;
	}
</style>
